package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.UserMapper;
import com.tanhua.model.db.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class UserApiImpl implements UserApi{
    @Autowired
    private UserMapper userMapper;

    //根据手机号查询用户
    @Override
    public User findByMobile(String mobile) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mobile",mobile);
        User user = userMapper.selectOne(queryWrapper);
        return user;
    }

    //保存用户，返回保存的用户ID
    @Override
    public Long save(User user) {
        userMapper.insert(user);
        System.out.println("保存的用户id="+user.getId());
        return user.getId();
    }

    //更新用户
    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    //查询所有
    @Override
    public List<User> findAll() {
        return userMapper.selectList(null);
    }
}
